import Enum from '../enum'

const Images = new Enum([
    {key: 'MAIN', name: '主图', value: 0},
    {key: 'DETAIL', name: '详情图', value: 1}
])
/**
 * 枚举类：商品类型
 * ProductTypeEnum
 */
export default Images;

/**
 * 获取主图
 * @param {array} images
 */
export function getMain(images) {
    if (images) {
        let filter = images.filter(i => i.type === Images.MAIN.value);
        if (filter && filter.length > 0) {
            return filter[0].url
        }
    }
    return '';
}

/**
 * 获取主图
 * @param {array} images
 */
export function getMainList(images) {
    if (images) {
        let filter = images.filter(i => i.type === Images.MAIN.value);
        if (filter && filter.length > 0) {
            return filter.map(r => r.url)
        }
    }
    return [];
}

/**
 * 获取主图
 * @param {array} images
 */
export function getDetail(images) {
    if (images) {
        let filter = images.filter(i => i.type === Images.DETAIL.value);
        if (filter && filter.length > 0) {
            return filter[0].url
        }
    }
    return '';
}

/**
 * 获取详情图
 * @param {array} images
 */
export function getDetailList(images) {
    if (images) {
        let filter = images.filter(i => i.type === Images.DETAIL.value);
        if (filter && filter.length > 0) {
            return filter.map(r => r.url)
        }
    }
    return [];
}